import cquery from '@dfeidao/atom-nodejs/db/complex-query';
// import format from '@dfeidao/atom-nodejs/dt/format';
// import console = require('console');
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../atom/config';
interface Message {
	student_name: string;
	// teacher_no: string;// 教师编号
	// section: string;// 节次
	// date: number;// 日期
	class_id: string;// 班级编号
	page_no: number;
	productid: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	const cq = cquery(action_id, session_id, systemid);


	const res = await cq
		.add_field('student', 'student_no', 'student_no')
		.add_field('student', 'student_name', 'student_name')
		.where_like('student', 'student_name', '%' + message.student_name + '%')
		.where_eq('class_student', 'class_id', message.class_id)
		.where_eq('student', 'status', '4')
		.where_eq('student', 'productid', message.productid)
		.outer_left_join('student', 'class_student', ['student_no', 'student_no'])
		.page(20, message.page_no)
		.exec();
	return { data: res };
}
